
import { HTableColumns } from "@/components/ant-ext-table/HTable";
import { Dispatch } from "redux";
import { HNavigate} from "@/config/route/route-func";
import HTag from "@/components/ant-ext/HTag";
import { Form } from "antd";
import { EnptTypeTag } from "@/const/const";
import HDataTable from "@/components/ant-ext-table/HDataTable";
import { DeleteOutlined, PlusSquareOutlined } from "@ant-design/icons";
import EnptList from "@/api/enpt-list";
import HAction from "@/components/common/HAction";
import { HDataTableSlice } from "@/components/ant-ext-table/redux/dataTableSlice";
import { useDispatch } from "react-redux";
import LoginUser from "@/config/user";
import EnterpriseEdit from "@/pages/enterpriseList/edit";



function getColumns(dispatch: Dispatch): HTableColumns<any> {
  return [
    {
      title: "id",
      dataIndex: 'id',
      width: '80px',
      fixed: 'left'
    }, {
      title: "企业名称",
      dataIndex: 'companyName',
    },
    {
      title: "企业类型",
      dataIndex: 'companyFlag',
      render: (value: any) => LoginUser.enptTypeToiD?.[Number(value)]
    },
    {
      title: "企业法人",
      dataIndex: 'legalPerson',
    },
    {
      title: "企业地址",
      dataIndex: 'address',
    },
    {
      title: "联系人",
      dataIndex: 'person',
    },
    {
      title: "联系方式",
      dataIndex: 'mobile',
    }, {
      title: '操作',
      width: '150px',
      dataIndex: 'action',
      render: (_, record) => (
        <div >
          <HAction type={"link"}
            empower={EnptList.EDIT}
            invalid
            action={() => dispatch!(HDataTableSlice.actions.doAction({
              action: EnptList.EDIT,
              rowKey: EnptList.RowKey,
              row: record
            }))}
            children={'修改'} />
            <HAction type={"link"}
            empower={EnptList.DET}
            invalid
            action={() => dispatch!(HDataTableSlice.actions.doAction({
              action: EnptList.DET,
              rowKey: EnptList.RowKey,
              row: record
            }))}
            children={'详情'} />
        </div>
      ),
    },
  ]
}

export default function EnterpriseList() {
  const [form] = Form.useForm()
  const dispatch = useDispatch()

  return <>
    <EnterpriseEdit />
    <div className="parent">
      <div className={"dataTable"}>
        <HDataTable
          option={[
            { key: EnptList.ADD, title: "新增", icon: <PlusSquareOutlined /> },
            {
              key: EnptList.DEL,
              title: "删除",
              // mode: "multi",
              mode: "only",
              icon: <DeleteOutlined style={{ color: "red" }} />,
              confirm: "是否要删除所选数据",
              action: (data) => {
                EnptList.delete({
                  body: { id: data.selectRowKeys[0] },
                  success: () => dispatch(HDataTableSlice.actions.setQueryParams({}))
                })
              }
            },
          ]}
          unSort={true}
          queryForm={{
            form: form,
            item: [
              { name: "content", label: "内容" }
            ]
          }}
          columns={getColumns(dispatch)} selectMethod={EnptList.selectTablePage}
          rowKey={EnptList.RowKey}
        />
      </div>
    </div>
  </>
}